<template>
  <div>
    <el-dialog
      :title="title"
      :visible="showDialog"
      width="30%"
      :show-close="false"
    >
      <el-form label-position="left" label-width="80px" :model="form">
        <el-form-item :label="numTitle">
          <el-input v-model="form.num" :placeholder="`请输入换绑${numTitle}。`"></el-input>
        </el-form-item>

        <el-form-item label="验证码" >
          <el-input v-model="form.code" placeholder="请输入验证码。">
            <el-button
              slot="append"
              @click="sendCode"
              :disabled="identification"
            >
              {{ identification ? `重新发送${time}` : '获取验证码' }}
            </el-button>
          </el-input>
        </el-form-item>

        <el-form-item :label="'密码'">
          <el-input v-model="form.in_userpassword" placeholder="请输入本网站的密码,初始密码为123456。"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('commandDialog', { title, result: false })"
          >取 消</el-button
        >
        <el-button type="primary" @click="$emit('changeNum', { title, form })"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui';

export default {
  data() {
    return {
      form: {
        num: '',
        code: '',
        in_userpassword: ''
      },
      identification: false,
      time: 60
    };
  },
  props: ['title', 'errorMsg', 'numTitle', 'showDialog'],
  methods: {
    identclick() {
      this.identification = true;
      let Time = setInterval(() => {
        if (this.time == 0) {
          this.identification = false;
          clearInterval(Time);
          this.time = 60;
        }
        this.time--;
      }, 1000);
    },
    sendCode() {
      if (!this.form.num) return Message.error(this.errorMsg);
      this.$emit('sendCode', { title: this.title, num: this.form.num });
      this.identclick();
    }
  }
};
</script>

<style scoped></style>
